package net.aydx84318.weather.bean;

import java.net.URLEncoder;
import java.text.MessageFormat;

import net.mihome.app.AppContext;
import net.mihome.app.utils.MiAsyncHttpResponseHandler;

import com.loopj.android.http.AsyncHttpClient;

/**
 * 从http://api.map.baidu.com/telematics/v3/weather?location=沈丘&output=json&ak=LMvroTgwaiilolKu62KMBkM4&mcode=07:77:2B:EF:24:4E:D1:ED:B1:57:9D:AC:1F:C1:C5:5E:7C:12:3D:24;net.mihome.app 获取天气预报
 * */

public class WeatherUtils {
	public final static String URL_S="http://api.map.baidu.com/telematics/v3/weather?location={2}&output=json&ak={0}&mcode={1}";
	public static String ak="LMvroTgwaiilolKu62KMBkM4";
	public static String mcode="07:77:2B:EF:24:4E:D1:ED:B1:57:9D:AC:1F:C1:C5:5E:7C:12:3D:24;net.mihome.app";
	public static void getWeather(String city, WeatherAsyncHttpResponseHandler weatherAsyncHttpResponseHandler){
		if(city==null){
			weatherAsyncHttpResponseHandler.onFailure(400, null, new Exception("无法获取城市信息"));
		}

        String url=MessageFormat.format(URL_S, ak, mcode,city);
		AppContext.ASYNC_HTTP_CLIENT.get(url,weatherAsyncHttpResponseHandler);
	}
}
